<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #tableAfterButtons>
        <a-button v-auth="['logistics:addressLib']" type="primary" status="warning"
                  @click="router.push(`/logistics/addressLib`)">地址库
        </a-button>
      </template>
      <template #ex_code_1="{ record }">
        <a-switch
          :checked-value="1"
          unchecked-value="0"
          @change="WaybillSeaClose($event, record.id)"
          :default-checked="record.ex_code_1 == 1"
        />
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import {ref, reactive} from 'vue'
import addressLibDetail from '@/api/logistics/addressLibDetail'
import {useRouter} from "vue-router";
import dictHelp from '@/utils/dicthelp'
import { Message } from '@arco-design/web-vue'
const WaybillSeaClose = async (ex_code_1, id) => {
    const response = await addressLibDetail.WaybillSeaClose({ id, ex_code_1})
    if (response.success) {
      Message.success(response.message)
    }
  }
const crudRef = ref()
const router = useRouter()
const options = reactive({
  id: 'address_lib_detail',
  pageLayout: 'fixed',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: false,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: '60%',
    layout: [{
      formType: 'grid-tailwind',
      colNumber: 3,
      cols: [{
        formList: [
          {dataIndex: "id",},
          {dataIndex: "address_lib_id",},
          {dataIndex: "customer_id",},
          {dataIndex: "about_id",},
          {dataIndex: "about_type",},
          {dataIndex: "type",},
          {dataIndex: "address_name",},
          {dataIndex: "code",},
          {dataIndex: "name",},
          {dataIndex: "tel",},
          {dataIndex: "company",},
          {dataIndex: "mobile",},
        ]
      },
        {
          formList: [
            {dataIndex: "city",},
            {dataIndex: "state",},
            {dataIndex: "country",},
            {dataIndex: "postcode",},
            {dataIndex: "address_1",},
            {dataIndex: "address_2",},
            {dataIndex: "address_3",},
          ]
        },
        {
          formList: [
            {dataIndex: "ex_code_1",},
            {dataIndex: "ex_code_2",},
            {dataIndex: "ex_code_3",},
            {dataIndex: "ex_code_4",},
            {dataIndex: "ex_code_5",},
            {dataIndex: "ex_code_6",},
            {dataIndex: "created_by",},
            {dataIndex: "updated_by",},
            {dataIndex: "created_at",},
            {dataIndex: "updated_at",},
            {dataIndex: "deleted_at",},
            {dataIndex: "remark",},
          ]
        }
      ]
    }]
  },
  api: addressLibDetail.getList,
  tabs: {
    dataIndex: "type",
    searchKey: "type",
    // defaultKey: 1
  },
  add: {
    show: true,
    api: addressLibDetail.save,
    auth: ['logistics:addressLibDetail:save']
  },
  edit: {
    show: true,
    api: addressLibDetail.update,
    auth: ['logistics:addressLibDetail:update']
  },
  delete: {
    show: true,
    api: addressLibDetail.deletes,
    realApi: addressLibDetail.realDeletes,
    auth: ['logistics:addressLibDetail:delete'],
  },
  import: {
    url: 'logistics/addressLibDetail/import',
    templateUrl: 'logistics/addressLibDetail/downloadTemplate', auth: [], role: [], text: '导入', show: true
  },
  recycleApi: addressLibDetail.recycle,
  recovery: {
    show: true,
    auth: ['logistics:addressLibDetail:recovery'],
    api: addressLibDetail.recoverys,
  },
  export: {show: true, url: 'logistics/addressLibDetail/export', auth: ['address:libDetails:export']},
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "客户地址",
    dataIndex: "is_customer",
    formType: "select",
    search: true,
    addDisplay: false,
    editDisplay: false,
    hide: true,
    dict: {
      data:[
        {
          value: 1,
          label: "是"
        },
        {
          value: 0,
          label: "否"
        },
      ]
    }
  },
  {
    title: "地址库",
    dataIndex: "address_lib_id",
    formType: "select",
    virtualListProps:{},
    search: true,
    commonRules: {
      required: true,
      message: "请输入地址库"
    },
    dict: {
      url: 'logistics/addressLib/list',
      props: {
        label: 'name',
        value: 'id'
      },
      translation: true
    },
    // multiple: true
  },
  {
    title: "用户",
    dataIndex: "customer_id",
    formType: "select",
    search: true,
    dict:dictHelp.customer,
  },
  {
    title: "关联id",
    dataIndex: "about_id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "关联模型",
    dataIndex: "about_type",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "地址类型",
    dataIndex: "type",
    formType: "select",
    search: true,
    hide: true,
    dict: {
      name: 'addressType',
      props: {label: "title", value: "key"},
      translation: true,
    }
    // addDisplay: false,
    // editDisplay: false,
    // hide: true
  },
  {
    title: "地址简称",
    dataIndex: "address_name",
    formType: "input",
    search: true
  },
  {
    title: "地址编码",
    dataIndex: "code",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入地址编码"
    }
  },
  {
    title: "联系人",
    dataIndex: "name",
    hide: true,
    commonRules: {
      required: true,
      message: "请输入联系人"
    },
    formType: "input"
  },
  {
    title: "联系电话",
    dataIndex: "tel",
    hide: true,
    formType: "input"
  },
  {
    title: "公司名",
    dataIndex: "company",
    hide: true,
    formType: "input"
  },
  {
    title: "联系手机",
    dataIndex: "mobile",
    hide: true,
    formType: "input",
    search: false
  },
  {
    title: "城市",
    dataIndex: "city",
    formType: "input"
  },
  {
    title: "省/州",
    dataIndex: "state",
    formType: "input"
  },
  {
    title: "国家",
    dataIndex: "country",
    formType: "select",
    dict: {
      name: 'countrys',
      props: {label: (i)=>i.title + '-' + i.key, value: "key"},
      // props: {label: "title", value: "key"},
    }
  },
  {
    title: "邮编",
    dataIndex: "postcode",
    formType: "input"
  },
  {
    title: "地址一",
    dataIndex: "address_1",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入地址一"
    }
  },
  {
    title: "地址二",
    dataIndex: "address_2",
    formType: "input",
    hide: true
  },
  {
    title: "地址三",
    dataIndex: "address_3",
    formType: "input",
    hide: true
  },
  {
    title: "海外仓过滤",
    dataIndex: "ex_code_1",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    // hide: true
  },
  {
    title: "扩展编码二",
    dataIndex: "ex_code_2",
    formType: "input",
    hide: true
  },
  {
    title: "扩展编码三",
    dataIndex: "ex_code_3",
    formType: "input",
    hide: true
  },
  {
    title: "扩展编码四",
    dataIndex: "ex_code_4",
    formType: "input",
    hide: true
  },
  {
    title: "扩展编码五",
    dataIndex: "ex_code_5",
    formType: "input",
    hide: true
  },
  {
    title: "扩展编码六",
    dataIndex: "ex_code_6",
    formType: "input",
    hide: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    search: false,
    addDisplay: false,
    editDisplay: false,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default {name: 'logistics:addressLibDetail'} </script>